package com.petmall.mapper;

import com.petmall.entity.Order;
import com.petmall.entity.Order_item;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * Created by pig2guang on 2017/4/20.
 */
@Mapper
public interface OrderMapper {

    @Select("select * from tb_order where user_id = #{user_id}")
    public List<Order> selectOrderByUserId(long user_id);

    @Select("select * from tb_order where order_id = #{order_id}")
    public Order selectOrderByOrderId(String order_id);

    @Select("select * from tb_order where user_id = #{user_id} and status= #{status} order by creat_time desc")
    public List<Order> selectOrderByStatus(@Param("status") int status, @Param("user_id") long user_id);

    @Select("select * from tb_order_item where order_id = #{order_id}")
    public List<Order_item> selectItemByOrderId(String order_id);

    @Insert("insert into tb_order(order_id,creat_time,status,item_total_price,post_fee,receiver_name,receiver_phone,receiver_address,user_id) values( #{order_id}, #{creat_time}, #{status}, #{item_total_price}, #{post_fee}, #{receiver_name}, #{receiver_phone}, #{receiver_address}, #{user_id} )")
    public void insertOrder(@Param("order_id") String order_id, @Param("creat_time") String creat_time, @Param("status") int status, @Param("item_total_price") double item_total_price, @Param("post_fee") double post_fee, @Param("receiver_name") String receiver_name, @Param("receiver_phone") String receiver_phone, @Param("receiver_address") String receiver_address, @Param("user_id") long user_id);

    @Insert("insert into tb_order_item(order_id,item_id,num) values(#{order_id}, #{item_id}, #{num} )")
    public void insertOrderItem(@Param("order_id") String order_id, @Param("item_id") long item_id, @Param("num") int num);

    @Update("update tb_order set status = #{status} where order_id = #{order_id}")
    public void updateOrderStatus(@Param("order_id") String order_id, @Param("status") int status);

    @Update("update tb_order set shipping_name = #{shipping_name}, shipping_code = #{shipping_code} where order_id = #{order_id}")
    public void updateOrderLogisticsInfo(@Param("order_id") String order_id, @Param("shipping_name") String shipping_name, @Param("shipping_code") String shipping_code);

    @Select("select * from tb_order order by creat_time desc")
    public List<Order> selectAllOrder();

    @Select("select * from tb_order_item where id=#{id}")
    public Order_item selectOrderItemById(long id);

}
